﻿using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using SharppiFlowEditor.models;
using SharppiFlowEditor.views;

namespace SharppiFlowEditor.controllers
{
    public class NodeDeleteController : AbstractController
    {

        public NodeDeleteController(AppView appView, AppModel appModel)
        {
            Model = appModel;
            View = appView;
        }

        override public void ViewMouseDown(object sender, MouseEventArgs e)
        {
            scrollOffset = View.document.ViewScrollPosition;
            if(View.document.GetNode((e.X - scrollOffset.X), (e.Y - scrollOffset.Y)) != null)
            {
                Model.DeleteNode(View.document.GraphDocument, View.document.GetNode((e.X - scrollOffset.X), (e.Y - scrollOffset.Y)));
            }
            else
            {
                Model.DeleteConnector(View.document.GraphDocument, View.document.getConnectorAtPoint(new PointF((e.X - scrollOffset.X), (e.Y - scrollOffset.Y))));
            }
            
            
            View.document.Invalidate();
            View.document.Update();
        }
    }
}
